<div class="layui-card">
    <!---->
    <div class="layui-header notselect">
        <div class="pull-left"><span>字典</span></div>
        <div class="pull-right margin-right-15 nowrap">
            <button data-modal="/system/dict/addDictUI" data-title="添加规格" class="layui-btn layui-btn-sm layui-btn-primary">添加字典</button>
            <button  data-action="/store/goods_spec/del.html" class="layui-btn layui-btn-sm layui-btn-primary">刷新数据</button>
        </div>
    </div>
    <div class="layui-card-body">
        <form autocomplete="off" class="layui-form layui-form-pane form-search" onsubmit="return false;">
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline">
                    <input id="type" name="type" value="" placeholder="类型" class="layui-input">
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">key</label>
                    <div class="layui-input-inline">
                        <input id="key" name="key" value="" placeholder="key" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <button class="layui-btn layui-btn-primary" onclick="doDictSearch();"><i class="layui-icon">&#xe615;</i> 搜 索</button>
            </div>
        </form>
        <script type="text/html" id="barTool">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <table class="layui-hide" id="dictTable" lay-filter="dictTable"></table>
    </div>
</div>
<script>
    var table;
    layui.use('table', function(){
        table = layui.table;
    });
    initDict();
    function initDict()
    {
        table.render({
            elem: '#dictTable'
            ,url:'/system/dict/ajax_list'
            ,title: '用户数据表'
            ,totalRow: true
            ,id: 'idTest'
            ,cols: [[
                {field:'id', title:'ID'}
                ,{field:'type', title:'类型'}
                ,{field:'name', title:'key'}
                ,{field:'value', title:'value'}
                ,{field:'descr', title:'描述'}
                ,{fixed: 'right', title:'操作', toolbar: '#barTool',}
            ]]
            ,page: true
            ,response: {
                statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
            },
            where: {type:$("#type").val(),key:$("#key").val()}
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                console.info(res)
                return {
                    "code":res.errorCode, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.totalElements, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
        });
        //监听行工具事件
        table.on('tool(dictTable)', function(obj){
            var data = obj.data;
            console.log(data)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.form.load("/system/dict/ajax_del",{id:data.id});
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                $.form.modal("/system/dict/updateDictUI",{id:data.id},"编辑");
            }
        });

    }
    function doDictSearch()
    {
        initDict();
    }
</script>